<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="事件类型" class="row-padding-bottom">
              <el-select
                v-model="filterField.typeId"
                clearable
                filterable
                placeholder="请选择"
              >
                <el-option
                  v-for="item in type"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="事件原因" class="row-padding-bottom">
              <el-select
                v-model="filterField.accidentId"
                clearable
                filterable
                placeholder="请选择"
              >
                <el-option
                  v-for="item in accident"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="事件程度" class="row-padding-bottom">
                <el-select
                  v-model="filterField.accidentRank"
                  clearable
                  filterable
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in rankOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-form-item>
          <el-button
            type="primary"
            icon="icon iconfont iconchazhao1"
            class="commonBtn"
            @click="searchList"
          ></el-button>
        </el-form-item> -->
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <exportBtn
                :dataLen="tableList.length"
                :filterField="filterField"
                api="api-s/report/export_QY_RIGHTS_ACCIDENT"
              ></exportBtn>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          v-loading="loading"
          stripe
          style="border: 1px solid #dfe6ec"
          @sort-change="sortChange"
        >
          <el-table-column
            prop="typeName"
            label="事件类型"
            align="center"
            :formatter="formatTd"
            min-width="110"
          ></el-table-column>
          <!-- <el-table-column prop="accidentName" label="事件原因" align="center" :formatter="formatTd"></el-table-column>  -->
          <el-table-column prop="accidentName" label="事件原因" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.accidentName"
                :columnName="'accidentName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="accidentDate"
            sortable="custom"
            label="事件时间"
            align="center"
            min-width="140"
          ></el-table-column>
          <el-table-column
            prop="industry"
            label="行业"
            align="center"
            :formatter="formatTd"
            min-width="110"
          ></el-table-column>
          <el-table-column
            prop="areaName"
            label="事件发生地区"
            align="center"
            :formatter="formatTd"
            min-width="130"
          ></el-table-column>
          <el-table-column prop="projectName" label="项目名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.projectName"
                :columnName="'projectName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="accidentRankDesc"
            label="事件程度"
            align="center"
            :formatter="formatTd"
            min-width="90"
          ></el-table-column>
          <el-table-column
            prop="creatorName"
            label="添加人"
            align="center"
            :formatter="formatTd"
            min-width="120"
          ></el-table-column>
          <el-table-column
            prop="createTime"
            sortable="custom"
            label="添加时间"
            align="center"
            :formatter="formatTd"
            min-width="140"
          >
            <template slot-scope="scope">
              <span>{{ common.GMTFormat(scope.row.createTime, true) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="left" fixed="right" width="80">
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-hasBtn="['bigEventJSF:detail', 'importEventSGF:detail']"
                @click="toDetail(scope.row)"
                >查看</el-link
              >
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>

        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>
<script>
import scrollTable from '@/mixin/scrollTable.js'
import emptyTable from '@/components/publicCom/emptyTable'
import Pagination from '@/components/publicCom/pagination'
import topTitle from '@/components/publicCom/topTitle'
export default {
  name: 'bigEvent',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '重大事件',
      advanced: false,
      rankOptions: [],
      type: [],
      accident: [],
      filterField: {
        sysAppCode: localStorage.getItem('judgeRoleCode'),
        typeId: '',
        accidentId: '',
        accidentRank: '',
      },
      requestUrl: 'api-r/rightsaccident/expand/listbycompany',
      tableList: [],
      loading: true,
      isShow: false,
    }
  },
  created() {
    this.getSelecData('RIGHTS_TYPE') //事件类型
    this.getSelecData('RIGHTS_ACCIDENT') //事件原因
    this.getRank()
    this.$nextTick(() => {
      this.$refs.pagination.getTableListData()
    })
  },
  components: {
    topTitle,
    emptyTable,
    Pagination,
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.pagination.getTableListData()
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getRank() {
      this.axios({
        method: 'post',
        url: 'api-r/rightsdispute/expand/getRank',
        data: {},
      })
        .then((response) => {
          this.rankOptions = response.data.result
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取事件程度数据失败',
            type: 'error',
          })
        })
    },
    getSelecData(type) {
      var url = 'api-bs/base/dicitem/findbytype'
      this.axios({
        method: 'post',
        url: url,
        data: { type: type },
      })
        .then((res) => {
          if (type == 'RIGHTS_TYPE') {
            this.type = res.data.result
          } else if (type == 'RIGHTS_ACCIDENT') {
            this.accident = res.data.result
          }
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取数据失败',
            type: 'error',
          })
        })
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    // 搜索
    searchList() {
      this.$nextTick(function () {
        this.$refs.pagination.getTableListData()
      })
    },
    toDetail(row) {
      this.$router.push({
        path: '/home/illegal/bigEventDetail',
        name: 'bigEventDetail',
        query: {
          id: row.id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/illegal/bigEvent',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>
<style lang="less" scoped>
.mainCon {
  top: 198px;
}
@import '../../../static/css/filterArea.less';
</style>
